Simplified Variables
You do not have to use the full path to a property in the `account`, `rest` or `http`. You can just use the property name, e.g. `{$subid}`.
Old Formal Tedious Way
HTTP parameters, REST parameters and account properties are canonically referred with their full path, for example:
Source | JSON Formal Path | XQuery Formal Path |
---|---|---|
HTTP URL parameters | http.parameters.userId |
$http//parameter[@name='userId']/text() |
REST URL parameters | rest.parameters.mode |
$rest//parameter[@name='mode']/text() |
Account properties | account.streetNumber |
$account/streetNumber/text() |
It is tedious to spell the same path again and again, especially in a large response.
Simplified Way
Since 1.8.1227, MockMotor allows to use the simplified form where only the variable name is required.
Formal | Simplified |
---|---|
JSON http.parameters.userId |
userId |
JSON rest.parameters.mode |
mode |
JSON account.streetNumber |
streetNumber |
XQuery $http//parameter[@name='userId']/text() |
$userId |
XQuery $rest//parameter[@name='mode']/text() |
$mode |
XQuery $account/streetNumber/text() |
$streetNumber |
All URL parameters from HTTP are placed into their own global variables.
All URL parameters from REST are placed into their own global variables.
All properties from account are placed into their own global variables.
If the same parameter name exists in REST and HTTP URLs, e.g. /accounts/{userId}?userId=100500
then the variable userId
($userId
) will have the value from REST, not HTTP.
If the same parameter name exists in REST/HTTP and account then the variable will have the value from REST, not account.
The simplified form can be used in any reaction field that supports scripting (matching, account selection, response payload, status, delay, …).
Use Example
JSON
Old reaction with the formal paths:
{
"transactionId": rest.parameters.tid,
"userId": account.userId
}
New reaction with the simplified paths:
{
"transactionId": tid,
"userId": userId
}
XQuery
Old reaction with the formal paths:
<Response>
<transactionId>{$rest//parameter[@name='tid']/text()}</transactionId>
<userId>{$account/userId/text()}</userId>
</Response>
New reaction with the simplified paths:
<Response>
<transactionId>{$tid}</transactionId>
<userId>{$userId}</userId>
</Response>
What about mockmeta
, input
and output
?
Only HTTP, REST and account are simplified.
Variables mockmeta
, input
(request
) and output
(response
) are not simplified.